#include<string>
template <typename T>
class bin_tree_node {
  public:
    T payload;                          // 节点负载
    bin_tree_node *left;                // 左子节点
    bin_tree_node *right;               // 右子节点

    // 节点的构造函数
    bin_tree_node(const T& value) {
        payload = value;
        left = nullptr;
        right = nullptr;
    }

    // 节点的析构函数
    ~bin_tree_node() {
        if (left)
            delete left;
        if (right)
            delete right;
    }
    // 获取左子节点（const 版本）
    const bin_tree_node* left_child() const
    {
        return left;
    }

    // 获取左子节点（非 const 版本）
    bin_tree_node* left_child()
    {
        return left;
    }

    // 设置当前节点的左子节点，返回新节点；已有左子节点时返回 nullptr
    bin_tree_node* left_child(const T& value)
    {
        if (left)
            return nullptr;

        // Create a new node with the given value
        left = new bin_tree_node(value);
        return left;
    }

    // 移除当前节点的左子树
    bool erase_left_subtree()
    {
        if (left == nullptr)
            return false;

        delete left;
        left = nullptr;
        return true;
    }

    // 获取右子节点（const 版本）
    const bin_tree_node* right_child() const
    {
        return right;
    }

    // 获取右子节点（非 const 版本）
    bin_tree_node* right_child()
    {
        return right;
    }

    // 设置当前节点的右子节点，返回新节点；已有右子节点时返回 nullptr
    bin_tree_node* right_child(const T& value)
    {
        if (right)
            return nullptr;

        // Create a new node with the given value
        right = new bin_tree_node(value);
        return right;
    }

    // 移除当前节点的右子树
    bool erase_right_subtree()
    {
        if (right == nullptr)
            return false;

        delete right;
        right = nullptr;
        return true;
    }
};

template <class bin_tree_node, typename T>
bin_tree_node* insert(bin_tree_node* root, const T& value)
{
    bin_tree_node* temp = new bin_tree_node(value);

    // 如果 root 为空，则新节点为根节点
    if (root == nullptr)
        return temp;

    // 依据二叉搜索树的特点寻找新节点的父节点。
    bin_tree_node *parent = nullptr, *curr = root;
    while (curr != nullptr) {
        parent = curr;
        if (curr->payload > value)
            curr = curr->left;
        else if (curr->payload < value)
            curr = curr->right;
        else {
            delete temp;
            return root;        // 如果树中已有相同的负载值的节点
        }
    }

    // 如果 value 更小，则将 temp 作为父节点的左子节点，否则为右子节点。
    if (parent->payload > value)
        parent->left = temp;
    else
        parent->right = temp;

    return root;
}

template <class bin_tree_node, typename T>
std::string search(bin_tree_node* root,
        const T& key, std::string &path){
    if (root == nullptr || root->payload == key)
        return "";

    // key 比 root 节点的负载值大
    if (root->payload < key){
        path += "R";
        return search(root->right, key, path);
    }
    // key 比 root 节点的负载值小
    if (root->payload > key){
        path += "L";
        return search(root->left, key, path);
    }
    return "n";
}
#include <iostream>     // for cin and cout
#include <sstream>      // for ostringstream
#include <string>       // for stod()
#include <cassert>      // for assert()
#include<vector>
using namespace std;
using my_bin_tree_node = bin_tree_node<int>;
int main()
{
    vector<double> a;
    my_bin_tree_node* root = nullptr;
    do {
        string buf;
        cin >> buf;
        double d;
        try {
            size_t sz;
            d = stod(buf, &sz);
        }
        catch (std::exception& e) {
            break;
        }
        a.push_back(d);
        root=insert(root,d);
    } while (true);
    size_t longestlength=0;
    double longest=-1;
    for (auto i=a.begin();i!=a.end();i++) {
        string path;
        search(root, *i, path);
        if(path.length()>=longestlength){
            longestlength=path.length();
            longest=*i;
        }
        cout<<*i<<" : "<<path<<endl;
    }
    cout<<longest<<endl;
    delete root;
}

